<template>
	<view>
		<view class="goods-list">
				<block v-for="(item,i) in goodsList" :key="i">
				<view @click="passGoodsdailte(item.goods_id)">
					 <My-goods :goods="item"></My-goods>
				</view>
			</block>
		</view>
	</view>
</template>

<script>

	export default {
	
		data() {
			return {
				queryObj:{
					query:"",
					cid:"",
					pagenum:1,
					pagesize:10,
				},
				total:0,
				goodsList:[],
				loding:false
				
			};
		},
	 onLoad(options){
		 this.queryObj.query = options.query || ''
		 this.queryObj.cid = options.cid || ''
		  this.getgoodsLists()
	   },
	 methods:{
		async getgoodsLists(cd){
			this.loding=true
			 const {data:res}= await uni.$http.get('/api/public/v1/goods/search',this.queryObj)
		    console.log(res)
			//   // if(res.meta.status!==200) return uni.$hsowMsg("暂时还没有该商品")
			  this.goodsList=[...this.goodsList,...res.message.goods]
			  this.total=res.message.total
			  this.queryObj.pagenum=res.message.pagenum
			  this.loding=false
			  cd&&cd()
		 },
		 passGoodsdailte(item){
		 	
		 	uni.navigateTo({
		 		url:"/subpkg/goods_detail/goods_detail?goods_id="+item
		 	})
		 }
		 

	 },
	 onReachBottom(){
		 if(this.queryObj.pagenum*this.queryObj.pagesize>=this.total) return uni.$showMsg("没有多余的数据了")
		 if(this.loding) return 
		 this.queryObj.pagenum++
		 this.getgoodsLists()
	 },
	 onPullDownRefresh(){
		 this.queryObj.pagenum=1
		 // this.total=0
		 this.loding=false
		 this.goodsList=[]
		 this.getgoodsLists(()=>uni.stopPullDownRefresh())
	 }
	}
</script>

<style lang="scss">
   
</style>
